package com.sgl.blog.service.impl;

import com.sgl.blog.mapper.AccountMapper;
import com.sgl.blog.pojo.BlogAccount;
import com.sgl.blog.service.AccountService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AccountServiceImpl implements AccountService {

    @Resource
    private AccountMapper accountMapper;

    @Override
    public void newAccount(BlogAccount account) {
        accountMapper.insert(account);
    }

    @Override
    public BlogAccount login(BlogAccount account) {
        List<BlogAccount> select = accountMapper.select(account);

        return select.size() == 0 ? null : select.get(0);

    }

    @Override
    public BlogAccount findById(Integer id) {
        return accountMapper.selectByPrimaryKey(id);
    }

    @Override
    public Boolean updateAccount(BlogAccount account) {
        return accountMapper.updateByPrimaryKey(account) > 0;
    }
}
